<template>
	<view>
		<u-card :full="false" :show-head="false">
			<view slot="body">
				<u-form :model="pass" ref="uForm" :error-type="['message']">
					<u-form-item label="原始密码" label-width="auto" prop="originPassword" :required="true">
						<u-input type="password" v-model="pass.originPassword" placeholder="请填写原始密码" />
					</u-form-item>
					<u-form-item label="重置密码" label-width="auto" prop="password" :required="true">
						<u-input type="password" v-model="pass.password" placeholder="请填写新密码" />
					</u-form-item>
					<u-form-item label="确认密码" label-width="auto" prop="confirmPassword" :required="true">
						<u-input type="password" v-model="pass.confirmPassword" placeholder="请确认新密码" />
					</u-form-item>
					<view class="padding"><u-button type="primary" @click="save">确认修改</u-button></view>
				</u-form>
			</view>
		</u-card>
	</view>
</template>

<script>
export default {
	data() {
		return {
			pass: {
				loginName: '',
				originPassword: '',
				password: '',
				confirmPassword: ''
			}, // 密码修改
			rules: {
				originPassword: [{ required: true, message: '必填', trigger: ['blur', 'change'] }],
				password: [{ required: true, message: '必填', trigger: ['blur', 'change'] }],
				confirmPassword: [
					{
						validator: (rule, value, callback) => {
							return this.pass.password === value;
						},
						message: '两次密输入不一致',
						trigger: ['blur', 'change']
					}
				]
			}
		};
	},
	onReady: function() {
		this.$refs['uForm'].setRules(this.rules);
	},
	methods: {
		save: function() {
			this.$refs['uForm'].validate(valid => {
				if (valid) {
					this.$request.post(`/admin/sys/user/changeTenantPassword`, this.pass, res => {
						this.$utils.showModal('密码修改成功！', () => {
							uni.navigateBack({
								delta: 1
							})
						}, false)
					}, true, true, true);
				}
			});
		}
	}
};
</script>

<style lang="scss" scoped></style>
